from pydantic import BaseModel
from typing import Generic, TypeVar, Optional

T = TypeVar('T')
class Response(BaseModel, Generic[T]):
    code: int
    message: str
    data: Optional[T] = None

class ResponseByPage(BaseModel, Generic[T]):
    code: int
    message: str
    total: int
    page: int
    total_pages:int
    page_size:int
    data: Optional[T] = None

async def create_response(code: int, message: str, data: Optional[T] = None):  
    return Response(code=code, message=message, data=data)

async def create_response_by_page(code: int, message: str, total: int, page: int, totalPages:int, pageSize:int, data: Optional[T] = None):  
    return ResponseByPage(code=code, message=message, total=total, page=page, page_size=pageSize, total_pages=totalPages, data=data)